#include <iostream>
#include <vector>
using namespace std;

void pro(vector<vector<int>>& grid,int posx,int posy)
{
	if((posx < 0) || (posx > grid.size()) || (posy < 0) || (posy > grid[0].size())){
		return;
	}
	if(grid[posx][posy] == 1){
		grid[posx][posy]=2;
		pro(grid,posx+1,posy);
		pro(grid,posx-1,posy);
		pro(grid,posx,posy+1);
		pro(grid,posx,posy-1);
	}
}


int numIslands(vector<vector<int>>& grid)
{
	int res=0;
	for(int i=0;i<grid.size();++i){
		for(int j=0;j<grid[0].size();++j){
			if(grid[i][j] == 1){
				pro(grid,i,j);
				++res;
			}
		}
	}
	return res;
}

int main(int argc, char *argv[])
{
	
	return 0;
}

